﻿<vi:PageView xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:vi="http://schemas.rhea.be/vidyano/2007/presentation"
             xmlns:controls="clr-namespace:RapidDownloader.Modules.Views.DownloadModule.Controls"
             xmlns:markup="clr-namespace:RapidDownloader.Modules.Views.Markup"
             x:Class="RapidDownloader.Modules.Views.DownloadModule.Views.NewDownload"
             mc:Ignorable="d" d:DesignHeight="365" d:DesignWidth="579" Title="LinkChecker">

    <vi:Container>
        <vi:Container.Resources>
            <markup:FormatSizeConverter x:Key="formatSize" />
        </vi:Container.Resources>

        <vi:Container.Template>
            <ControlTemplate>
                <ContentPresenter Content="{Binding Items[0], RelativeSource={RelativeSource TemplatedParent}}" />
            </ControlTemplate>
        </vi:Container.Template>

        <DockPanel vi:ViewModel.Scope="Module.Context" Margin="10">
            <DockPanel DockPanel.Dock="Top">
                <StackPanel>
                    <DockPanel>
                        <TextBlock Text="Name :  " FontWeight="Bold" VerticalAlignment="Center" Width="100" />
                        <TextBox vi:ViewModel.Scope="DownloadTitle" />
                    </DockPanel>
                    <DockPanel Margin="0, 5, 0, 0">
                        <TextBlock Text="Target folder :  " FontWeight="Bold" VerticalAlignment="Center" Width="100" />
                        <Button DockPanel.Dock="Right" Margin="5, 0, 0, 0" Width="24" Content="..." vi:ViewModel.Scope="BrowseForDownloadFolder" />
                        <TextBox vi:ViewModel.Scope="DownloadFolder" IsReadOnly="True" />
                    </DockPanel>
                </StackPanel>
            </DockPanel>

            <DockPanel DockPanel.Dock="Top" Margin="0, 10" LastChildFill="False">

                <Button DockPanel.Dock="Left" vi:ViewModel.Scope="PasteLinksFromClipboard">
                    <StackPanel Orientation="Horizontal" Margin="5">
                        <Image Source="../Resources/Paste.ico" Width="16" Height="16" VerticalAlignment="Center" Margin="0, 0, 10, 0" />
                        <TextBlock Text="Paste links ..." />
                    </StackPanel>
                </Button>

                <Button DockPanel.Dock="Left" vi:ViewModel.Scope="Clear" CommandParameter="{Binding SelectedItems, ElementName=filesList}" Margin="10, 0, 0, 0">
                    <StackPanel Orientation="Horizontal" Margin="5">
                        <Image Width="16" Height="16" VerticalAlignment="Center" Margin="0, 0, 10, 0">
                            <Image.Style>
                                <Style TargetType="Image">
                                    <Setter Property="Source" Value="../Resources/Clear.ico" />
                                    <Style.Triggers>
                                        <DataTrigger Binding="{Binding HasSelectedItems, ElementName=filesList}" Value="True">
                                            <Setter Property="Source" Value="../Resources/Remove.ico" />
                                        </DataTrigger>
                                    </Style.Triggers>
                                </Style>
                            </Image.Style>
                        </Image>
                        <TextBlock>
                            <TextBlock.Style>
                                <Style TargetType="TextBlock">
                                    <Setter Property="Text" Value="Clear links ..." />
                                    <Style.Triggers>
                                        <DataTrigger Binding="{Binding HasSelectedItems, ElementName=filesList}" Value="True">
                                            <Setter Property="Text" Value="Remove links ..." />
                                        </DataTrigger>
                                    </Style.Triggers>
                                </Style>
                            </TextBlock.Style>
                        </TextBlock>
                    </StackPanel>
                </Button>

                <Button DockPanel.Dock="Right" vi:ViewModel.Scope="Download">
                    <StackPanel Orientation="Horizontal" Margin="5">
                        <Image Source="../Resources/Download.png" Width="16" Height="16" VerticalAlignment="Center" Margin="0, 0, 10, 0" />
                        <TextBlock Text="Start download ..." />
                    </StackPanel>
                </Button>
            </DockPanel>

            <controls:ListViewWithSelectedItemsNotification vi:ViewModel.Scope="Files" Grid.IsSharedSizeScope="True" x:Name="filesList">
                <controls:ListViewWithSelectedItemsNotification.Template>
                    <ControlTemplate TargetType="{x:Type ListView}">
                        <Border Background="WhiteSmoke" BorderBrush="#FFAAAAAA" BorderThickness="1" CornerRadius="5">
                            <ScrollViewer HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto">
                                <ItemsPresenter />
                            </ScrollViewer>
                        </Border>
                    </ControlTemplate>
                </controls:ListViewWithSelectedItemsNotification.Template>
                <controls:ListViewWithSelectedItemsNotification.ItemsPanel>
                    <ItemsPanelTemplate>
                        <WrapPanel />
                    </ItemsPanelTemplate>
                </controls:ListViewWithSelectedItemsNotification.ItemsPanel>
                <controls:ListViewWithSelectedItemsNotification.ItemContainerStyle>
                    <Style TargetType="{x:Type ListViewItem}">
                        <Setter Property="Margin" Value="5" />
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="{x:Type ListViewItem}">
                                    <Grid>
                                        <Border CornerRadius="5" BorderThickness="1" BorderBrush="#FFA1A1A1" x:Name="border">
                                            <Border.Background>
                                                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                                    <GradientStop Color="#FFEAEAEA"/>
                                                    <GradientStop Color="#FF818181" Offset="1"/>
                                                </LinearGradientBrush>
                                            </Border.Background>
                                            <ToggleButton Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}" IsChecked="{Binding IsSelected, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}">
                                                <ToggleButton.Template>
                                                    <ControlTemplate TargetType="ToggleButton">
                                                        <ContentPresenter />
                                                    </ControlTemplate>
                                                </ToggleButton.Template>
                                            </ToggleButton>
                                        </Border>
                                    </Grid>

                                    <ControlTemplate.Triggers>
                                        <Trigger Property="IsSelected" Value="True">
                                            <Setter Property="BorderBrush" Value="Transparent" TargetName="border" />
                                            <Setter Property="Opacity" Value="0.6" TargetName="border" />
                                        </Trigger>

                                        <DataTrigger Binding="{Binding CanDownload}" Value="False">
                                            <Setter Property="Background" TargetName="border">
                                                <Setter.Value>
                                                    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                                        <GradientStop Color="#FFFF4343" Offset="0"/>
                                                        <GradientStop Color="#FF950000" Offset="1"/>
                                                    </LinearGradientBrush>
                                                </Setter.Value>
                                            </Setter>
                                        </DataTrigger>

                                        <DataTrigger Binding="{Binding CanDownload}" Value="True">
                                            <Setter Property="Background" TargetName="border">
                                                <Setter.Value>
                                                    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                                        <GradientStop Color="#FF63FF43" Offset="0"/>
                                                        <GradientStop Color="#FF199500" Offset="1"/>
                                                    </LinearGradientBrush>
                                                </Setter.Value>
                                            </Setter>
                                        </DataTrigger>
                                    </ControlTemplate.Triggers>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </controls:ListViewWithSelectedItemsNotification.ItemContainerStyle>
                <controls:ListViewWithSelectedItemsNotification.ItemTemplate>
                    <DataTemplate>
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition SharedSizeGroup="width" />
                            </Grid.ColumnDefinitions>

                            <Grid Margin="5">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto" />
                                    <ColumnDefinition Width="Auto" />
                                    <ColumnDefinition Width="10" />
                                    <ColumnDefinition />
                                </Grid.ColumnDefinitions>

                                <Grid.RowDefinitions>
                                    <RowDefinition />
                                    <RowDefinition />
                                </Grid.RowDefinitions>

                                <Image Height="20" Width="20" RenderOptions.BitmapScalingMode="HighQuality" Grid.RowSpan="2" VerticalAlignment="Center" Margin="0,0,5,0" Source="{Binding ProviderIcon}" />

                                <TextBlock Text="File :" FontWeight="Bold" Grid.Column="1" />
                                <TextBlock Text="{Binding FileName}" TextTrimming="CharacterEllipsis" Grid.Column="3" />

                                <TextBlock Text="Size :" FontWeight="Bold" Grid.Column="1" Grid.Row="1" />
                                <TextBlock Text="{Binding Size, Converter={StaticResource formatSize}}" TextTrimming="CharacterEllipsis" Grid.Row="1" Grid.Column="3" />
                            </Grid>
                        </Grid>
                    </DataTemplate>
                </controls:ListViewWithSelectedItemsNotification.ItemTemplate>
            </controls:ListViewWithSelectedItemsNotification>
        </DockPanel>
    </vi:Container>
</vi:PageView>